watch(
  () => state.formData.会议类型,
  (newData, oldData) => {
    axios
      .get("/conference/api/title", { params: { type: newData } })
      .then((res) => res.data.results)
      .then((conference) =>
        conference.map((i) => {
          return {
            label: i.title,
            value: i.id,
          };
        })
      )
      .then((conference) => (state.会议标题Options = conference));
  }
);

watch(
  () => state.formData.会议标题,
  (newData, oldData) => {
    axios
      .get("/conference/api/number", {
        params: { id: newData },
      })
      .then((res) => res.data.results)
      .then((conference) => conference.map((i) => i.number)[0])
      .then((conference) => (state.formData.会议期次 = conference));

    axios
      .get("/conference/api/plan", {
        params: { id: newData },
      })
      .then((res) => res.data.results)
      .then((conference) => conference.map((i) => i.plan)[0])
      .then((conference) => (state.会议方案 = conference));

    axios
      .get("/conference/api/content", {
        params: { id: newData },
      })
      .then((res) => res.data.results)
      .then((conference) => conference.map((i) => i.content)[0])
      .then((conference) => (state.会议内容 = conference));

    axios
      .get("/conference/api/preset_time", {
        params: { id: newData },
      })
      .then((res) => res.data.results)
      .then((conference) => conference.map((i) => i.preset_time)[0])
      .then((conference) => (state.formData.会议时间 = conference));

    axios
      .get("/conference/api/place", {
        params: { id: newData },
      })
      .then((res) => res.data.results)
      .then((conference) => conference.map((i) => i.place)[0])
      .then((conference) => (state.formData.会议地点 = conference));

    // 主持人，缺少数据待验证
    // TODO:
    axios
      .get("/conference/api/host", {
        params: { id: newData },
      })
      .then((res) => res.data.results)
      .then((conference) => conference.map((i) => i.host)[0])
      .then((h) => console.log(h));

    //   TODO:待改正
    axios
      .get("/issue/api/name", {
        params: { conference_id: newData },
      })
      .then((res) => res.data.results)
      .then((issue) =>
        issue.map((i) => {
          return {
            label: i.name,
            value: i.id,
          };
        })
      )
      .then((issue) => (state.议题名称Options = issue));

    axios
      .get("/conference/api/plan", {
        params: { id: newData },
      })
      .then((res) => res.data.results)
      .then((conference) => conference.map((i) => i.plan)[0])
      .then((conference) => (state.会议方案 = conference));

      axios
      .get("/issue/api/id",{params:{conference_id:newData}})
      .then((res) => res.data.results)
      .then((issue) => {
        axios
          .get("/advice_attent/viewsets/")
          .then((res) => res.data.results)
          .then(advice_attent=>advice_attent.filter(i=>issue.some(j=>i.issue_id===j.id)))
          .then((advice_attent) => {
                axios
                .get("/danwei/viewsets/")
                .then((res) => res.data.results)
                .then((danwei) =>danwei.filter(i=>advice_attent.some(j=>i.id===j.danwei_id)))
                .then((danwei) =>danwei.map((i) => {
                    return {
                      label: i.name,
                      value: i.id,
                    };
                }))
                .then(danwei=>state.参会单位Options=danwei)
        })
    })
});

// TODO: 待测试
watch(
  () => state.formData.议题名称,
  (newData, oldData) => {
    axios
      .get("/material/api/title", { issue_id: newData })
      .then((res) => res.data.results)
      .then((material) =>
        material.map((i) => {
          return {
            label: i.title,
            value: i.id,
          };
        })
      )
      .then((material) => (state.关联文档Options = material));


      axios
      .get("/advice_attent/api/meeting_time", { params: { issue_id: newData } })
      .then((res) => res.data.results)
      .then((data) => {
        const meeting_time = data.map((i) => new Date(i.meeting_time));
        console.log(meeting_time);
        if (meeting_time.length > 0) {
          const minTime = meeting_time.reduce(
            (min, time) => (time < min ? time : min),
            meeting_time[0]
          );
          state.formData.到会时间 = minTime;
        }
      });

  }
);


// TODO: 待测试
watch(
  () => state.formData.关联文档,
  (newData, oldData) => {
    axios
      .get("/attachment/api/title", { material_id: newData })
      .then((res) => res.data.results)
      .then((attachment) =>
        attachment.map((i) => {
          return {
            label: i.title,
            value: i.id,
          };
        })
      )
      .then((attachment) => (state.附件Options = attachment));
  }
);



axios
  .get("/material/api/title", { params: { issue_id: 1 } })
  .then((res) => res.data.results)
  .then((material) =>
    material.map((i) => {
      return {
        label: i.title,
        value: i.id,
      };
    })
  )
  .then((material) => (state.关联文档Options = material));

axios
  .get("/attachment/api/title", { params: { material_id: 1 } })
  .then((res) => res.data.results)
  .then((attachment) =>
    attachment.map((i) => {
      return {
        label: i.title,
        value: i.id,
      };
    })
  )
  .then((attachment) => (state.附件Options = attachment));
